using System.Collections.Generic;
using System.Security.Claims;
using IdentityServer4;
using IdentityServer4.Models;
using IdentityServer4.Test;

namespace www.sso.com
{
    public class Config
    {
        //定义系统中的资源
        public static IEnumerable<IdentityResource> GetIdentityResources()
        {
            return new List<IdentityResource>
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),
            };
        }

        public static IEnumerable<Client> GetClients()
        {
            // 客户端凭据
            return new List<Client>
            {
                // OpenID Connect implicit 客户端 (MVC)
                new Client
                {
                    ClientId = "a.com",
                    ClientName = "a.com",
                    AllowedGrantTypes = GrantTypes.Implicit,

                    RedirectUris = { "http://139.224.24.146:9002/signin-oidc" },
                    PostLogoutRedirectUris = { "http://139.224.24.146:9002" },
                    //禁用授权页面
                    RequireConsent = false,
                    //运行访问的资源
                    AllowedScopes =
                    {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile
                    }
                },
				new Client
				{
					ClientId = "b.com",
					ClientName = "b.com",
					AllowedGrantTypes = GrantTypes.Implicit,

					RedirectUris = { "http://localhost:5001/signin-oidc" },
					PostLogoutRedirectUris = { "http://localhost:5001" },
                    RequireConsent = false,//禁用 consent确认页面。
                    //运行访问的资源
                    AllowedScopes =
					{
						IdentityServerConstants.StandardScopes.OpenId,
						IdentityServerConstants.StandardScopes.Profile
					}
				},
				new Client
				{
					ClientId = "c.com",
					ClientName = "c.com",
					AllowedGrantTypes = GrantTypes.Implicit,
                    RequireConsent = false,//禁用 consent确认页面。
					RedirectUris = { "http://localhost:5003/signin-oidc" },
					PostLogoutRedirectUris = { "http://localhost:5003" },
                    //运行访问的资源
                    AllowedScopes =
					{
						IdentityServerConstants.StandardScopes.OpenId,
						IdentityServerConstants.StandardScopes.Profile
					}
				}
            };
        }

        //测试用户
        public static List<TestUser> GetUsers()
        {
            return new List<TestUser>
            {
                new TestUser
                {
                    SubjectId = "1",
                    Username = "admin",
                    Password = "123456",

                    Claims = new List<Claim>
                    {
                        new Claim("name", "admin"),
                        new Claim("website", "http://localhost:5001")
                    }
                },
                new TestUser
                {
                    SubjectId = "2",
                    Username = "jimmyzheng",
                    Password = "123456",

                    Claims = new List<Claim>
                    {
                        new Claim("name", "jimmyzheng"),
                        new Claim("website", "http://139.224.24.146:9002")
                    }
                },
                new TestUser
                {
                    SubjectId = "3",
                    Username = "jimmy",
                    Password = "123456",

                    Claims = new List<Claim>
                    {
                        new Claim("name", "jimmy"),
                        new Claim("website", "http://localhost:5003")
                    }
                }
            };
        }
    }
}